package com.ruoyi.web.controller.ability;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GoodsTags;
import com.ruoyi.system.service.IGoodsTagsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品标签关系Controller
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/system/tags")
public class GoodsTagsController extends BaseController
{
    @Autowired
    private IGoodsTagsService goodsTagsService;

    /**
     * 查询商品标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:tags:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsTags goodsTags)
    {
        startPage();
        List<GoodsTags> list = goodsTagsService.selectGoodsTagsList(goodsTags);
        return getDataTable(list);
    }

    /**
     * 导出商品标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:tags:export')")
    @Log(title = "商品标签关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsTags goodsTags)
    {
        List<GoodsTags> list = goodsTagsService.selectGoodsTagsList(goodsTags);
        ExcelUtil<GoodsTags> util = new ExcelUtil<GoodsTags>(GoodsTags.class);
        util.exportExcel(response, list, "商品标签关系数据");
    }

    /**
     * 获取商品标签关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tags:query')")
    @GetMapping(value = "/{goodsTagId}")
    public AjaxResult getInfo(@PathVariable("goodsTagId") Long goodsTagId)
    {
        return success(goodsTagsService.selectGoodsTagsByGoodsTagId(goodsTagId));
    }

    /**
     * 新增商品标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:tags:add')")
    @Log(title = "商品标签关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsTags goodsTags)
    {
        return toAjax(goodsTagsService.insertGoodsTags(goodsTags));
    }

    /**
     * 修改商品标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:tags:edit')")
    @Log(title = "商品标签关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsTags goodsTags)
    {
        return toAjax(goodsTagsService.updateGoodsTags(goodsTags));
    }

    /**
     * 删除商品标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:tags:remove')")
    @Log(title = "商品标签关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsTagIds}")
    public AjaxResult remove(@PathVariable Long[] goodsTagIds)
    {
        return toAjax(goodsTagsService.deleteGoodsTagsByGoodsTagIds(goodsTagIds));
    }
}
